layui.use(['form', 'jquery', 'layer', 'table', 'laydate', 'upload'], function() {
	var form = layui.form;
	var $ = layui.$;
	var table = layui.table;
	var layer = layui.layer;
	var laydate = layui.laydate;
	var upload = layui.upload;
	var lay_filter = 'tpl_site_config';
	form.render();
	var save_config = function(value, id) {
		var url = $('form[lay-filter="' + lay_filter + '"]').attr('action'),
			field = {
				site_config_id: id,
				config_value: value
			}
		send_info(url, field, function(data) {
			if(data.code == 0) {
				layer.msg('自动保存，保存成功', {
					icon: 1,
					anim: 6
				});
			} else {
				layer.msg(data.msg, {
					icon: 2,
					anim: 6
				});
			}
		})
	}
	form.on('radio(*)', function(data) {
		var id = $(this).attr('data-id')
		value = data.value;
		save_config(value, id);
	});
	$('form[lay-filter="' + lay_filter + '"]').on('focus', 'input[type="text"],input[type="number"],textarea', function() {
		$(this).attr('data-old_value', $(this).val());
		return false;
	})
	$('form[lay-filter="' + lay_filter + '"]').on('blur', 'input[type="text"],input[type="number"],textarea', function() {
		var id = $(this).attr('data-id'),
			value = $(this).val(),
			old_value = $(this).attr('data-old_value');
		if(value != old_value) {
			$(this).attr('data-old_value', value);
			save_config(value, id);
		}
		return false;
	})
})